﻿#ifndef WORKER_H
#define WORKER_H

#include <QThread>
#include <QEventLoop>
#include <QTimer>
#include "../comm/mediaoutput.h"
#include "rtpsend.h"
#include "mediacapturer.h"

class Worker : public QThread
{
    Q_OBJECT
public:
    explicit Worker(QString *ip);
    ~Worker();

    void msSleep(int ms);
    void setRunState(bool start);

    //解析得到sps pps
    void parseSPS_PPS(AVCodecContext *videoCtx);

    //avPacket传递至RTP发送线程 type为AVPacketType, 自定义的音视频类型
    void sendPacketToRtpSender(AVPacket *packet, AVPacketType type);

    //实时音视频发送，重要
    void doTaskRealStart();
    void doTaskRealStop();

protected:
    void run() override;

public:
    VideoOutput *videoOutput;

    RtpPacketSender *rtpSender; //RTP发送线程
    VideoCapturer *videoCapturer; //视频实时捕捉线程
    AudioCapturer *audioCapturer; //音频实时捕捉线程

private:
    bool isRun;
    QString* destIP; //指向外部SenderWidget的QString destIP

    // 序列参数集（Sequence Parameter Set）和图像参数集（Picture Parameter Set）
    //sps pps
    char *spsFrame; int spsLen;
    char *ppsFrame; int ppsLen;
};

#endif // WORKER_H
